
import re
from time import sleep

from playwright.sync_api import Playwright, sync_playwright
import time
import random

from config.config import get_upload_dir_path
from model.ProConfModel import ProConfModel
from service.KeepAliveService import set_keep_alive_storage, get_storage_path_by_pro, get_act_storage_path_by_pro
from tools.Func import wait_for_file_content


def do_login_test() -> None:
    with sync_playwright() as playwright:
        browser = playwright.firefox.launch(headless=False)
        context = browser.new_context()
        page = context.new_page()
        page.goto("https://rematdispp.crccep.cn/",wait_until="networkidle", timeout=15000)
        page.locator("#divSmsForm div").filter(
            has_text="中国铁建分供商财资外部用户委托职评人员相关方合作方外部专家客户及供应商 股份总部 中土集团 十一局 十二局 大桥局 十四局 十五局 十六局 十七局 十八局 十九").get_by_role(
            "button").click()
        page.get_by_role("link", name="客户及供应商").click()
        page.get_by_role("textbox", name="手机号").fill("13373515113")
        page.get_by_role("button", name="获取验证码").click()
        code = wait_for_file_content(get_upload_dir_path() + "tjyl_code",max_attempts=50,interval=5)
        page.get_by_role("textbox", name="验证码").fill(code)
        page.get_by_role("button", name="登录").click()

        context.storage_state(path="E:/Python/pythonProject/pythonProject/upload/tjyl_kjx.json")





        # ---------------------
        page.goto("https://rematdispp.crccep.cn/detail/512326510997295104",wait_until="networkidle",timeout=15000)

        context.close()
        browser.close()


def get_detail():
    with sync_playwright() as playwright:
        browser = playwright.chromium.launch(headless=False)

        context = browser.new_context(
            storage_state="E:/Python/pythonProject/pythonProject/upload/tjyl_kjx.json")
        page = context.new_page()


        # ---------------------
        page.goto("https://rematdispp.crccep.cn/detail/512326510997295104",wait_until="networkidle",timeout=25000)

        sleep(600)
        context.close()
        browser.close()



if __name__ == '__main__':
    get_detail()